﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.Windows.Forms;

namespace SimTank
{
    [XmlRoot("AttackQueueObject")]
    public class attackQueueObject
    {
        [XmlElement("SpellName")]
        public String spellName;
        [XmlElement("SpellID")]
        public int SpellID;
        [XmlElement("buffPresentSpellID")]
        public int buffPresentSpellID;
        [XmlElement("buffPresentStack")]
        public int buffPresentStack;
        [XmlElement("debuffPresentSpellID")]
        public int debuffPresentSpellID;
        [XmlElement("debuffStack")]
        public int debuffStack;
        [XmlElement("resourceMin")]
        public int resourceMin;
        [XmlElement("resourceMax")]
        public int resourceMax;
        [XmlElement("class")]
        public String usableby;
        [XmlIgnore]
        public static Hashtable spellNameHash;

        public ListViewItem ToListViewItem()
        {
            StringBuilder conditionText = new StringBuilder();
            
            if (buffPresentSpellID != 0)
            {
                conditionText.Append(spellNameHash[buffPresentSpellID]);
                if (buffPresentStack > 1)
                    conditionText.Append(" Stacks > " + buffPresentStack);
                else if (buffPresentStack == 1)
                    conditionText.Append(" Present");
                else if (buffPresentStack == 0)
                    conditionText.Append(" Not Present");
            }
            if (debuffPresentSpellID != 0)
            {
                conditionText.Append(spellNameHash[debuffPresentSpellID]);
                if (debuffStack > 1)
                    conditionText.Append(" Stacks < " + debuffStack);
                else if (debuffStack == 1)
                    conditionText.Append(" Applied");
                else if (debuffStack == 0)
                    conditionText.Append(" Not Applied");
            }
            if (resourceMax > 0 || resourceMin > 0)
            {
                switch (usableby)
                {
                    case "Warrior":
                        conditionText.Append("Rage ");
                        break;
                    case "Druid":
                        conditionText.Append("Rage ");
                        break;
                    case "Paladin":
                        conditionText.Append("Mana % ");
                        break;
                    case "Death Knight":
                        conditionText.Append("Runic Power ");
                        break;
                }
                if (resourceMin > 0)
                {
                    conditionText.Append("less than ");
                    conditionText.Append(resourceMin);
                }
                else if (resourceMax > 0)
                {
                    conditionText.Append("at most ");
                    conditionText.Append(resourceMax);
                }
                
            }

            return new ListViewItem(new String[] {spellName, 
                                                  conditionText.ToString(), 
                                                  SpellID.ToString(), 
                                                  buffPresentSpellID.ToString(),
                                                  buffPresentStack.ToString(),
                                                  debuffPresentSpellID.ToString(),
                                                  debuffStack.ToString(),
                                                  resourceMin.ToString(),
                                                  resourceMax.ToString()
            });
        }

        public attackQueueObject(ListViewItem input)
        {
            spellName = input.SubItems[0].Text;
            if (input.SubItems.Count > 1)
            {
                Int32.TryParse(input.SubItems[2].Text, out SpellID);
                Int32.TryParse(input.SubItems[3].Text, out buffPresentSpellID);
                Int32.TryParse(input.SubItems[4].Text, out buffPresentStack);
                Int32.TryParse(input.SubItems[5].Text, out debuffPresentSpellID);
                Int32.TryParse(input.SubItems[6].Text, out debuffStack);
                Int32.TryParse(input.SubItems[7].Text, out resourceMin);
                Int32.TryParse(input.SubItems[8].Text, out resourceMax);
            }
        }

        public attackQueueObject() { }
    }
}
